package helpers;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import entities.Domain;

public class CrawlerHelper {
    
    public static String getWhois(String name) {
	    	String url = "http://www.whois.com/whois/" + name;
			String whois = "";
			try {
				Connection conn = Jsoup.connect(url);
				Document doc = conn
						.header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
						.header("accept-Language", "en-us,en;q=0.5")
						.header("host", "whoisainfo.net")
						.timeout(3000)
						.get();
						
						
				
				
				whois = doc.select(".whois_result").html();
				
				if (!whois.isEmpty()) {
					whois = whois.replaceAll("[<]{1}(a)[^>]+[>]{1}", "").replaceAll("<\\/a>", "");
					//whois = whois.replaceAll("(src=\")", "src=\"http://www.whoismind.com");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
            
            return whois;
    }
	
}
